package com.yyjj.hangqing.activity;

import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.aries.ui.view.title.TitleBarView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.yyjj.hangqing.R;
import com.yyjj.hangqing.adapter.HuoQiBaoAdapter;
import com.yyjj.hangqing.adapter.ZhiShuBaoAdapter;
import com.yyjj.hangqing.api.Api;
import com.yyjj.hangqing.entity.BaseTResp;
import com.yyjj.hangqing.entity.HuoQiBaoEntity;
import com.yyjj.hangqing.entity.ZhiShuBaoEntity;

import java.util.ArrayList;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseRefreshLoadActivity;
import tech.com.commoncore.constant.ApiConstant;
import tech.com.commoncore.view.SpaceItemDecoration;

/**
 * 指数宝
 */
@Route(path = "/hq/ZhiShuBao")
public class ZhiShuBaoActivity extends BaseRefreshLoadActivity{

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("指数宝");
    }

    @Override
    public int getContentLayout() {
        return R.layout.hq_activity_zhi_shu_bao;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        mRecyclerView.addItemDecoration(new SpaceItemDecoration(1));

    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return new ZhiShuBaoAdapter(R.layout.hq_item_zhishubao_list);
    }

    @Override
    public void loadData(int page) {
       // https://d.wanjinig.cn/new_api/Funs/treasure?sort=0&desc=desc&type=all&is_cache=1
        ViseHttp.GET(Api.ZHISHUBAO_URL)
                .baseUrl(ApiConstant.BASE_URL)
                .addParam("sort","0")
                .addParam("desc","desc")
                .addParam("type","all")
                .addParam("is_cache","1")
                .request(new ACallback<BaseTResp<ArrayList<ZhiShuBaoEntity>>>() {
                    @Override
                    public void onSuccess(BaseTResp<ArrayList<ZhiShuBaoEntity>> data) {
                        if(data.code ==1 && data.data != null){
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),data.data,null);
                        }else{
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),null,null);
                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),null,null);
                    }
                });
    }
}
